#include <jni.h>
#include <string>
#include <sys/socket.h>
#include <unistd.h>

#include <android/hardware_buffer.h>
#include <android/hardware_buffer_jni.h>

extern "C"
JNIEXPORT jobject JNICALL
Java_com_example_remotedraw_MainActivity_recvHardwareBufferFromUnixSocket(JNIEnv *env, jclass clazz, jint fd) {
    AHardwareBuffer* hardwareBuffer = NULL;
    AHardwareBuffer_recvHandleFromUnixSocket(fd, &hardwareBuffer);
    jobject obj = AHardwareBuffer_toHardwareBuffer(env, hardwareBuffer);
    AHardwareBuffer_release(hardwareBuffer);
    return obj;
}